﻿using System;
using System.Collections.Generic;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Scripting.Function.Context
{
    public class FindFunctionsNode : FuncNode
    {
        public FindFunctionsNode()
            : base("findfunc")
        {
        }

        public override object Evaluate()
        {
            if (Parameters.Count < 1)
            {
                foreach (string key in DefaultDependencyManager.Instance.FunctionManager.Functions.Keys)
                {
                    Console.WriteLine(key);
                }
            }
            else
            {
                List<string> results = new List<string>();
                string funcName = Convert.ToString(
                    Parameters[0].Evaluate());
                foreach (string key in DefaultDependencyManager.Instance.FunctionManager.Functions.Keys)
                {
                    if (key.IndexOf(funcName) >= 0)
                    {
                        Console.WriteLine(key);
                    }
                }
            }

            return string.Empty;
        }
    }
}
